package com.itheima07;

//异常的使用案例
public class YiChangChuYi {
    public static void main(String[] args) {
        int code = 0;
        try {
            function(1);
            code = 200;
        } catch (ArithmeticException e) {
            code = 404;
        } catch (ArrayIndexOutOfBoundsException e) {
            code = 500;
        } catch (NullPointerException e) {
            code = 300;
        }
        System.out.println("程序结束!");
        System.out.println(code);
    }


    public static void function(int num) throws ArithmeticException, ArrayIndexOutOfBoundsException, NullPointerException {
        if (num == 1) {
            //制造异常
            System.out.println(3 / 0);
        }
        if (num == 2) {
            //制造异常
            int[] array = new int[3];
            System.out.println(array[4]);
        }
        if (num == 3) {
            String s = null;
            System.out.println(s.length());
        }
        System.out.println("程序正常运行!");
    }

}
